package com.atguigu.lease.common.exception;


import com.atguigu.lease.common.result.Result;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result error(RuntimeException e) {
        e.printStackTrace();
        return Result.fail();
    }
    // 有自定义异常
    @ExceptionHandler(LeaseException.class)
    public Result leaseFail(LeaseException leaseException){
        leaseException.printStackTrace();
        return Result.build(null,leaseException.getCodeEnum());
    }
    }
